package org.itzheng.myrxframe.http.rxjava;

import io.reactivex.Observable;
import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Title:Rx帮助类，使用 Lambda<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2019-4-10.
 */
public class RxHelper {
    /**
     * 在io线程操作，接收后，返回到主线程
     * .subscribeOn(Schedulers.io())
     * .observeOn(AndroidSchedulers.mainThread())
     *
     * @param <T>
     * @return
     */
    public static <T> ObservableTransformer<T, T> observableIO2Main() {
        return upstream -> {
            Observable<T> observable = upstream.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread());
            return observable;
        };
    }

    public static <T> ObservableTransformer<T, T> io() {
        return upstream -> {
            Observable<T> observable = upstream.subscribeOn(Schedulers.io())
                    .observeOn(Schedulers.io());
            return observable;
        };
    }
}
